﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpGameLibrary
{
    public class Layer
    {
        #region Fields

        Tuple<string, int, int>[,] tiles;   //bridge to the original tile with the name of the tileset with the pos X and pos Y on it
        string name;

        #endregion

        #region Get / Set

        public string IndexName
        {
            get
            {
                return this.name;
            }
        }

        #endregion

        #region Constructor

        public Layer(string name, int tilesWidth, int tilesHeight)
            : this(name, Layer.initializeTiles(tilesWidth, tilesHeight))
        {
        }

        public Layer(string name, Tuple<string, int, int>[,] tiles)
        {
            this.tiles = tiles;
            this.name = name;
        }

        #endregion

        #region private static Init

        private static Tuple<string, int, int>[,] initializeTiles(int tilesWidth, int tilesHeight)
        {
            Tuple<string, int, int>[,] tiles = new Tuple<string, int, int>[tilesWidth, tilesHeight];

            for (int y = 0; y < tilesHeight; y++)
                for (int x = 0; x < tilesWidth; x++)
                    tiles[x, y] = new Tuple<string, int, int>(null, -1, -1);

            return tiles;
        }

        #endregion

        #region public Tile Methods

        public string getTilesetName(int tileX, int tileY)
        {
            return this.tiles[tileX, tileY].Item1;
        }

        public int getTilePosXInTileset(int tileX, int tileY)
        {
            return this.tiles[tileX, tileY].Item2;
        }

        public int getTilePosYInTileset(int tileX, int tileY)
        {
            return this.tiles[tileX, tileY].Item3;
        }

        public void setTile(string tileset, int tilesetX, int tilesetY, int tileX, int tileY)
        {
            this.tiles[tileX, tileY] = Tuple.Create<string, int, int>(tileset, tilesetX, tilesetY);
        }

        public void removeTile(int tileX, int tileY)
        {
            this.tiles[tileX, tileY] = Tuple.Create<string, int, int>(null, -1, -1);
        }

        #endregion
    }
}
